//
//  BaseNavController.swift
//  KTDouYu
//
//  Created by CoolKi on 16/5/5.
//  Copyright © 2016年 CoolKi. All rights reserved.
//

import UIKit

class BaseNavController: UINavigationController {

    private lazy var panGesture : UIPanGestureRecognizer = {
       let panGesture = UIPanGestureRecognizer(target: self.interactivePopGestureRecognizer?.delegate, action: "handleNavigationTransition:")
        panGesture.delegate = self
        return panGesture
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.addGestureRecognizer(panGesture)
        self.interactivePopGestureRecognizer?.enabled = false
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    override class func initialize(){
        
        let navigationC = UINavigationBar.appearance()
        navigationC.barTintColor = UIColor.kt_colorWithHexString("f56f22", alpha: 1)
        //navigationC.barTintColor = UIColor(red: 255, green: 97, blue: 0, alpha: 1)
    }
    
    //有bug的方法//实现这个方法，图片轮播起无数据
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        if self.childViewControllers.count >= 1 {
            let backBtn = UIButton(type: .Custom)
            backBtn.setBackgroundImage(UIImage(named: "del_left"), forState: .Normal)
            print(self)
            backBtn.addTarget(self, action: "back", forControlEvents: .TouchUpInside)
            backBtn.sizeToFit()
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backBtn)
            
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    func back(){
        self.popViewControllerAnimated(true)
    }

}


extension BaseNavController : UIGestureRecognizerDelegate{
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return self.childViewControllers.count > 1
    }
    
    
}





